package qianting.news.wemedia.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qianting.news.apis.models.wemedia.dtos.ChannelDto;
import qianting.news.apis.models.wemedia.pojos.WmChannel;
import qianting.news.common.entity.State;
import qianting.news.wemedia.service.WmChannelService;

@Api(tags = "频道管理")
@RestController
@RequestMapping("/channel")
public class WmchannelController {

    @Autowired
    private WmChannelService wmChannelService;

    //查询所有的频道
    @ApiOperation(value = "查询所有的频道")
    @GetMapping("/list")
    public State findAll(){
        return wmChannelService.findAll();
    }

    //根据名称模糊查询频道
    @ApiOperation(value = "根据名称模糊查询频道")
    @PostMapping("/findByNameAndPage")
    public State findByNameAndPage(@RequestBody ChannelDto dto){
        return wmChannelService.findByNameAndPage(dto);
    }

    //新增一个频道
    @ApiOperation(value = "新增一个频道")
    @PostMapping("/save")
    public State insert(@RequestBody WmChannel adChannel){
        return wmChannelService.insert(adChannel);
    }

    //更新频道
    @ApiOperation(value = "更新频道")
    @PostMapping("/update")
    public State update(@RequestBody WmChannel adChannel){
        return wmChannelService.update(adChannel);
    }

    //删除频道
    @ApiOperation(value = "删除频道")
    @GetMapping("/del/{id}")
    public State delete(@PathVariable("id") Integer id){
        return wmChannelService.delete(id);
    }

}